<?php

session_status();
if (isset($_SESSION['name'])) {

    echo "<script>window.location.href='../../index.php';</script>";
}
else {

}
?>



<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <link rel="stylesheet" href="../../static/css/login.css"/>
    <link rel="stylesheet" href="../../static/css/util.css"/>
    <link rel="stylesheet" href="../../static/js/layui/css/layui.css"/>
    <style rel="stylesheet">
        #icon {
            margin-top: -45px;
            margin-left: 5px;
            position: absolute;
            font-size: 30px;
            color: #9D53F2;
        }

        #login {
            color: white;
        }
    </style>
</head>

<body>
<div class="limiter">

    <div class="container-login100" style="background-image: url('../../static/images/bg-01.jpg');">
        <div class="wrap-login100 p-l-55 p-r-55 p-t-65 p-b-54">
            <form class="login100-form validate-form">
                <span class="login100-form-title p-b-49">Buglist用户登录</span>

                <div class="wrap-input100 validate-input m-b-23" data-validate="请输入用户名">
                    <span class="label-input100">用户名</span>
                    <input class="input100" type="text" name="name" id="name" placeholder="请输入用户名" autocomplete="off">
                    <i class="layui-icon " id="icon">&#xe66f;</i>
                </div>

                <div class="wrap-input100 validate-input" data-validate="请输入密码">
                    <span class="label-input100">密码</span>
                    <input class="input100" type="password" name="pass" id="password" placeholder="请输入密码">
                    <i class="layui-icon " id="icon">&#xe673;</i>
                </div>

                <div class="text-right p-t-8 p-b-31">
                    <a href="javascript:">忘记密码？</a>
                </div>

                <div class="container-login100-form-btn">
                    <div class="wrap-login100-form-btn">
                        <div class="login100-form-bgbtn"></div>
                        <a class="login100-form-btn" id="login">登 录</a>
                    </div>
                </div>


            </form>
        </div>
    </div>
</div>
<script type="text/javascript"src="../../static/js/jquery-3.3.1.min.js"></script>
<script type="text/javascript" src ="../../static/js/config.js"></script>
<script type="text/javascript" src="../../static/js/layui/layui.all.js"></script>

<script type="text/javascript">

    window.onload=function(){

        document.onkeydown=function(ev){
            var event=ev ||event
            if(event.keyCode==13){
                login();
            }
        }
    }

    $("#login").click(function () {
        login();
    });

    //登录函数
    function login() {
        $name = $("#name").val();
        $password = $("#password").val();
        if ($name.length == 0) {
            layer.msg("用户名不能为空！");
            return false;
        }
        if ($password.length == 0) {
            layer.msg("密码不能为空！");
            return false;

        }
        else {
            $.ajax({
                type: 'post',
                cache: 'false',
                url: "../controller/login.php",
                data: {
                    "name": $name,
                    "password": $password,
                },
                dataType:'json',
                success: function (data) {


                    if (data.code == '200') {
                        layer.msg(data.message);
                        window.location.href="../../index.php?name="+$name;
                    }
                    else {
                        layer.msg(data.message);
                    }

                },
                error: function (res) {
                    console.log(res);
                    layer.msg("登录失败！")

                }

            })
        }


    }


</script>